package com.ruoyi.web.controller.community;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.community.domain.PoliceList;
import com.ruoyi.community.service.IPoliceListService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 查询Controller
 * 
 * @author ruoyi
 * @date 2022-04-25
 */
@RestController
@RequestMapping("/police")
public class PoliceListController extends BaseController
{
    @Autowired
    private IPoliceListService policeListService;

    /**
     * 查询查询列表
     */
    @GetMapping("/list")
    public List<PoliceList> list(PoliceList policeList)
    {
        policeList.setCommunityId((long)SecurityUtils.getCommunityId());
        List<PoliceList> list = policeListService.selectPoliceListList(policeList);
        return list;
    }

    /**
     * 导出查询列表
     */
    @Log(title = "查询", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PoliceList policeList)
    {
        List<PoliceList> list = policeListService.selectPoliceListList(policeList);
        ExcelUtil<PoliceList> util = new ExcelUtil<PoliceList>(PoliceList.class);
        return util.exportExcel(list, "查询数据");
    }

    /**
     * 获取查询详细信息
     */
    @GetMapping(value = "/{policeId}")
    public AjaxResult getInfo(@PathVariable("policeId") Long policeId)
    {

        return AjaxResult.success(policeListService.selectPoliceListById(policeId));
    }

    /**
     * 新增查询
     */
    @Log(title = "查询", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PoliceList policeList)
    {
        policeList.setCommunityId((long)SecurityUtils.getCommunityId());
        return toAjax(policeListService.insertPoliceList(policeList));
    }

    /**
     * 修改查询
     */
    @Log(title = "查询", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PoliceList policeList)
    {
        return toAjax(policeListService.updatePoliceList(policeList));
    }

    /**
     * 删除查询
     */
    @Log(title = "查询", businessType = BusinessType.DELETE)
	@DeleteMapping("/{policeIds}")
    public AjaxResult remove(@PathVariable Long[] policeIds)
    {
        return toAjax(policeListService.deletePoliceListByIds(policeIds));
    }
}
